package edu.joe.demo.conventer;

import component.NodePersistenceComponent;
import conventer.MibNodeConverter;
import edu.joe.demo.entity.MibDbNode;
import model.MibNode;

public class MibDbNodeConverter extends MibNodeConverter<MibDbNode> {
    @Override
    public MibNode toBean(MibDbNode entity) {
        try {
            MibNode node = NodePersistenceComponent.fromJson(entity.getJson());
            return node;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public MibDbNode toEntity(MibNode bean) {
        MibDbNode node = new MibDbNode();
        convert(bean, node);
        node.setJson(NodePersistenceComponent.toJson(bean));
        return node;
    }
}
